package com.jinlia.show.modules.system.controller.sys;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jinlia.show.modules.base.model.form.RoleForm;
import com.jinlia.show.modules.base.model.po.SysRolePO;
import com.jinlia.show.modules.base.model.po.SysUserPO;
import com.jinlia.show.modules.base.model.query.RolePageQuery;
import com.jinlia.show.modules.base.model.query.UserPageQuery;
import com.jinlia.show.modules.base.system.entity.SysRole;
import com.jinlia.show.modules.base.system.service.SysRoleMapperService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("role")
public class SysRoleController {

    @Autowired
    SysRoleMapperService sysRoleMapperService;

    /**
     * 添加角色
     * @param sysRole
     * @return
     */
    @PostMapping("add")
    public ResponseEntity add(@RequestBody RoleForm sysRole) {
        sysRoleMapperService.addSysRole(sysRole);
        return ResponseEntity.ok(sysRole);
    }
    /**
     * 修改角色
     * @param sysRole
     * @return
     */
    @PostMapping("update")
    public ResponseEntity update(@RequestBody RoleForm sysRole) {
        sysRoleMapperService.updateSysRole(sysRole);
        return ResponseEntity.ok(sysRole);
    }
    @GetMapping("list")
    public List<SysRole> goodsList() {
        List<SysRole> list = sysRoleMapperService.list();
        return list;
    }

    /**
     * 分页查询角色
     * @param queryParams
     * @return
     */
    @PostMapping("/page")
    public ResponseEntity<IPage<SysRolePO>> getUserPage(@RequestBody RolePageQuery queryParams
    ) {
        IPage<SysRolePO> tt = sysRoleMapperService.getRolePage(queryParams);
        return ResponseEntity.ok(tt);
    }
    @PostMapping("users/{id}")
    public ResponseEntity addUser(@PathVariable("id") Long id,@RequestBody RoleForm roleForm) {
        roleForm.setId(id);
        sysRoleMapperService.addUser(roleForm);
        return ResponseEntity.ok(roleForm);
    }
    @PostMapping("users/del/{id}")
    public ResponseEntity delUser(@PathVariable("id") Long id,@RequestBody RoleForm roleForm) {
        roleForm.setId(id);
        sysRoleMapperService.delUser(roleForm);
        return ResponseEntity.ok(roleForm);
    }
}
